/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_CORE_PLATFORM_SPIN_H__
#define __XOS_CORE_PLATFORM_SPIN_H__

#include "include.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos
{

    class spin
    {
    public:
        spin()
        {
            //pthread_spin_init( &m_spin, PTHREAD_PROCESS_PRIVATE );
            pthread_mutex_init( &m_mutex, 0 );
        }
        ~spin()
        {
            //pthread_spin_destroy( &m_spin );
            pthread_mutex_destroy( &m_mutex );
        }

    protected:
        //pthread_spinlock_t m_spin;
        //OSSpinLock m_spin;
        pthread_mutex_t m_mutex;

    public:
        int un_lock()
        {
            int nRet = 0;
            //pthread_spin_unlock( &m_spin );
            pthread_mutex_unlock( &m_mutex );
            return nRet;
        }
        int lock()
        {
            int nRet = 0;
            //pthread_spin_lock( &m_spin );
            pthread_mutex_lock( &m_mutex );
            return nRet;
        }
    };

} // xos

#endif // __XOS_CORE_PLATFORM_SPIN_H__
